<?php
class Comment extends AppModel {
	var $name = 'Comment';
	var $validate = array(
		'link_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				'allowEmpty' => false,
			),
		),
		'user_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				'allowEmpty' => false,
			),
		),
		'content' => array(
			'lenght' => array(
				'rule' => array('minLength',20),
				'allowEmpty' => false,
				'message'=>'Escribe un comentario mas largo'
			),
		)
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Link' => array(			
			'counterCache' => 'comment_count',
		),
		'User' => array()
	);
	

	// responses
	
//	var $hasMany = array(
//		'Link' => array(
//			'className' => 'Link',
//			'foreignKey' => 'category_id',
//			'dependent' => false,
//			'conditions' => '',
//			'fields' => '',
//			'order' => '',
//			'limit' => '',
//			'offset' => '',
//			'exclusive' => '',
//			'finderQuery' => '',
//			'counterQuery' => ''
//		),
//		'Children'=>array(
//			'className' => 'Category',
//			'foreignKey' => 'parent',
//			'dependent' => true,
//		)
//	);
//	
//	var $belongsTo=array(
//		'Parent' => array(
//			'className' => 'Category',
//			'foreignKey' => 'parent',
//			'dependent' => false
//		)
//	);

	function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
		if(isset($conditions['Comment.parent'])&&isset($conditions['Comment.link_id'])&&($conditions['Comment.parent']==0)){
			return $this->Link->field('comment_count',array('id'=>$conditions['Comment.link_id']));
		}

		return parent::paginateCount($conditions, $recursive, $extra);
	}
	
}
?>